#pragma once

#include <memory>
#include <ProElempath.h>
#include "wProElempath.hpp"


namespace witotk{

	template<ProElempathItemtype tp>
	struct ProElempathItem_T
	{
		int m_i;
		ProElempathItem_T(int a):m_i(a){}
		
		operator ProElempathItem ()
		{
			ProElempathItem aa = {tp,m_i}; 
			return aa;
		}
	};

	typedef ProElempathItem_T<PRO_ELEM_PATH_ITEM_TYPE_ID> ID_;
	typedef ProElempathItem_T<PRO_ELEM_PATH_ITEM_TYPE_INDEX> INDEX_;

	class wPath
	{
	public:
		wPath():m_pathdata(NULL),size(0),buffsize(0)
		{

		}
		~wPath()
		{
			delete[] m_pathdata;
		}
		wPath& operator[](const ProElempathItem& tp)
		{
			if(m_pathdata == NULL)
			{
				m_pathdata = new ProElempathItem[4];
				buffsize = 4;
			}
			if(size == buffsize)
			{
				ProElempathItem * tmp = m_pathdata;
				buffsize *= 2;
				m_pathdata = new ProElempathItem[buffsize];
				memcpy_s(m_pathdata,size * sizeof(ProElempathItem),
					tmp,size * sizeof(ProElempathItem));
				delete[] tmp;
			}
			m_pathdata[size] = tp;
			size++;

			return *this;
		}

		operator ProElempathItem*()
		{
			return m_pathdata;
		}
		short size;
		ProElempathItem * m_pathdata;
	private: 
		short buffsize;
	};

	class wProElempath:public wOHandle<ProElempath>
	{
	public:
		wProElempath()
		{
			ProElempathAlloc(&m_data);
		}
		~wProElempath()
		{
			ProElempathFree(&m_data);
		}

		wProElempath(ProElempath suf):wOHandle<ProElempath>(suf)
		{
		}

		void SetData(const wPath & path)
		{
			ProError error = ProElempathDataSet(m_data,path.m_pathdata,path.size);
			PROE_THROW(error,"SetData");
		}

	};

	typedef	std::tr1::shared_ptr<wProElempath> wProElempath_ptr;

	typedef	wCollectionshared_ptr<wCollection<wProElempath>> wProElempathCollection_ptr;

	typedef	wCollection<wProElempath> wProElempathCollection;


}